<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单位" prop="workPlace">
        <el-select v-model="queryParams.workPlace" placeholder="请选择工作单位" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_group"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位" prop="posts">
        <el-select v-model="queryParams.posts" placeholder="请选择职位" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_group"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="出生日期" prop="birth">
        <el-input
          v-model="queryParams.birth"
          placeholder="请输入出生日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="钢瓶瓶号" prop="cylinderNumber">
        <el-input
          v-model="queryParams.cylinderNumber"
          placeholder="请输入钢瓶瓶号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="钢瓶状态" prop="cylinderStatus">
        <el-select v-model="queryParams.cylinderStatus" placeholder="请选择钢瓶状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="应充介质" prop="gasMedia">
        <el-select v-model="queryParams.gasMedia" placeholder="请选择应充介质" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="钢瓶重量" prop="weight">
        <el-input
          v-model="queryParams.weight"
          placeholder="请输入钢瓶重量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="钢瓶容积" prop="volume">
        <el-input
          v-model="queryParams.volume"
          placeholder="请输入钢瓶容积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属气站" prop="belongingGasStation">
        <el-select v-model="queryParams.belongingGasStation" placeholder="请选择所属气站" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="钢瓶生产日期" prop="manufactureDate">
        <el-date-picker clearable
          v-model="queryParams.manufactureDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择钢瓶生产日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="钢瓶报废日期" prop="scrapDate">
        <el-date-picker clearable
          v-model="queryParams.scrapDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择钢瓶报废日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="充装气站" prop="fillingStation">
        <el-select v-model="queryParams.fillingStation" placeholder="请选择充装气站" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="充装介质" prop="fillingMedium">
        <el-select v-model="queryParams.fillingMedium" placeholder="请选择充装介质" clearable>
          <el-option
            v-for="dict in dict.type.sys_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="充装时间" prop="fillingTime">
        <el-date-picker clearable
          v-model="queryParams.fillingTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择充装时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入单位ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:filling:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:filling:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:filling:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:filling:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fillingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="工作单位" align="center" prop="workPlace">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_group" :value="scope.row.workPlace"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="工号" align="center" prop="userName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="职位" align="center" prop="posts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_group" :value="scope.row.posts"/>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birth" />
      <el-table-column label="钢瓶瓶号" align="center" prop="cylinderNumber" />
      <el-table-column label="钢瓶状态" align="center" prop="cylinderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.cylinderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="应充介质" align="center" prop="gasMedia">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.gasMedia"/>
        </template>
      </el-table-column>
      <el-table-column label="钢瓶重量" align="center" prop="weight" />
      <el-table-column label="钢瓶容积" align="center" prop="volume" />
      <el-table-column label="所属气站" align="center" prop="belongingGasStation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.belongingGasStation"/>
        </template>
      </el-table-column>
      <el-table-column label="钢瓶生产日期" align="center" prop="manufactureDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.manufactureDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="钢瓶报废日期" align="center" prop="scrapDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scrapDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="充装气站" align="center" prop="fillingStation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.fillingStation"/>
        </template>
      </el-table-column>
      <el-table-column label="充装介质" align="center" prop="fillingMedium">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.fillingMedium"/>
        </template>
      </el-table-column>
      <el-table-column label="充装时间" align="center" prop="fillingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fillingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="单位ID" align="center" prop="deptId" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:filling:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:filling:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改充装信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="工作单位" prop="workPlace">
          <el-select v-model="form.workPlace" placeholder="请选择工作单位">
            <el-option
              v-for="dict in dict.type.sys_job_group"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="职位" prop="posts">
          <el-select v-model="form.posts" placeholder="请选择职位">
            <el-option
              v-for="dict in dict.type.sys_job_group"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birth">
          <el-input v-model="form.birth" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="钢瓶瓶号" prop="cylinderNumber">
          <el-input v-model="form.cylinderNumber" placeholder="请输入钢瓶瓶号" />
        </el-form-item>
        <el-form-item label="钢瓶状态" prop="cylinderStatus">
          <el-select v-model="form.cylinderStatus" placeholder="请选择钢瓶状态">
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="应充介质" prop="gasMedia">
          <el-select v-model="form.gasMedia" placeholder="请选择应充介质">
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="钢瓶重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入钢瓶重量" />
        </el-form-item>
        <el-form-item label="钢瓶容积" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入钢瓶容积" />
        </el-form-item>
        <el-form-item label="所属气站" prop="belongingGasStation">
          <el-select v-model="form.belongingGasStation" placeholder="请选择所属气站">
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="钢瓶生产日期" prop="manufactureDate">
          <el-date-picker clearable
            v-model="form.manufactureDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择钢瓶生产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="钢瓶报废日期" prop="scrapDate">
          <el-date-picker clearable
            v-model="form.scrapDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择钢瓶报废日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="充装气站" prop="fillingStation">
          <el-select v-model="form.fillingStation" placeholder="请选择充装气站">
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="充装介质" prop="fillingMedium">
          <el-select v-model="form.fillingMedium" placeholder="请选择充装介质">
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="充装时间" prop="fillingTime">
          <el-date-picker clearable
            v-model="form.fillingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择充装时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="单位ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入单位ID" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFilling, getFilling, delFilling, addFilling, updateFilling } from "@/api/system/filling";

export default {
  name: "Filling",
  dicts: ['sys_job_status', 'sys_job_group'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 充装信息表格数据
      fillingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idNumber: null,
        workPlace: null,
        sex: null,
        userName: null,
        phone: null,
        posts: null,
        birth: null,
        cylinderNumber: null,
        cylinderStatus: null,
        gasMedia: null,
        weight: null,
        volume: null,
        belongingGasStation: null,
        manufactureDate: null,
        scrapDate: null,
        fillingStation: null,
        fillingMedium: null,
        fillingTime: null,
        userId: null,
        deptId: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询充装信息列表 */
    getList() {
      this.loading = true;
      listFilling(this.queryParams).then(response => {
        this.fillingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        idNumber: null,
        workPlace: null,
        sex: null,
        userName: null,
        phone: null,
        posts: null,
        birth: null,
        cylinderNumber: null,
        cylinderStatus: null,
        gasMedia: null,
        weight: null,
        volume: null,
        belongingGasStation: null,
        manufactureDate: null,
        scrapDate: null,
        fillingStation: null,
        fillingMedium: null,
        fillingTime: null,
        userId: null,
        deptId: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加充装信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFilling(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改充装信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFilling(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFilling(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除充装信息编号为"' + ids + '"的数据项？').then(function() {
        return delFilling(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/filling/export', {
        ...this.queryParams
      }, `filling_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
